package top.stacktrace.order.service;

import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.messaging.Message;
import org.springframework.stereotype.Component;
import top.stacktrace.order.domain.Order;

import java.util.function.Consumer;

@Slf4j
@Component
public class ConsumerService {
    @Autowired
    private OrderService orderService;
    @Bean
    public Consumer<Message<Order>> order(){
        return order -> {
            log.info("get order:{}", JSON.toJSONString(order.getPayload()));
            orderService.payForOrder(order.getPayload());
        };
    }
}
